package com.fastfood.model.blo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.fastfood.model.dao.FoodDAO;
import com.fastfood.model.dto.Food;
import com.fastfood.util.DBConnectionPool;

public class FoodBLO {

	private FoodDAO dao = new FoodDAO();
	
	public List<Food> getAllFoods() {
		List<Food> foods = null;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			foods = dao.getAllFoods(conn);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return foods;
	}
	
	public boolean addFood(Food food) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.addFood(conn, food);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public boolean updateFood(Food food) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.updateFood(conn, food);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public boolean deleteFood(Food food) {
		boolean result = false;
		Connection conn = DBConnectionPool.getConnectionPool().getConnection();
		if (conn != null) {
			result = dao.deleteFood(conn, food);
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
}
